import type { App } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHashHistory } from 'vue-router';

const Login = () => import('@/views/login/index.vue');
const Home = () => import('@/views/home/index.vue');

export const LAYOUT = () => import('@/layout/layoutMain.vue');

const basicRoutes: any[] = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
  },
  {
    meta: {
      title: '',
      icon: '',
    },
    path: '/layout',
    name: 'Layout',
    component: LAYOUT,
    redirect: '/layout/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: Home,
      },
    ],
  },
  {
    path: '/',
    redirect: '/login',
  },
];

// app router
export const router = createRouter({
  history: createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH),
  routes: basicRoutes as unknown as RouteRecordRaw[],
  strict: true,
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// config router
export const setupRouter = (app: App<Element>) => {
  app.use(router);
};

export default router;
